package cn.com.egova.web.action;

import cn.com.egova.domain.Customer;
import cn.com.egova.domain.Dict;
import cn.com.egova.domain.Linkman;
import cn.com.egova.domain.PageBean;
import cn.com.egova.service.LinkmanService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;
import com.sun.deploy.util.LinkMouseListener;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

/**
 * Created by yuanchao on 2020/5/26.
 */
public class LinkmanAction extends BaseAction implements ModelDriven<Linkman> {
    private static final long serialVersionUID = 230450956903445l;
    private Linkman linkman = new Linkman();
    private LinkmanService linkmanService;

    public void setLinkmanService(LinkmanService linkmanService) {
        this.linkmanService = linkmanService;
    }

    @Override
    public Linkman getModel() {
        return linkman;
    }


    public String findByPage() {
        DetachedCriteria criteria = DetachedCriteria.forClass(Linkman.class);
        String lkmName = linkman.getLkm_name();
        if (lkmName != null && !lkmName.trim().isEmpty()) {
            criteria.add(Restrictions.like("lkm_name", "%" + lkmName + "%"));
        }

        Customer customer = linkman.getCustomer();
        if (customer != null && customer.getCust_id() != null) {
            criteria.add(Restrictions.eq("customer.cust_id", customer.getCust_id()));
        }

        PageBean<Linkman> page = linkmanService.findByPage(this.getPageCode(), this.getPageSize(), criteria);
        this.setValueStack("page", page);
        return "page";
    }
}
